#!/opt/php/bin/php -d display_errors=1
<?php
require_once 'TVB/Message/BaseConsumer.php';
require_once 'TVB/mytvplus/portal_service/common/bootstrap.php';
require_once 'TVB/mytvplus/portal_service/common/AppConfiguration.class.php';
require_once 'TVB/mytvplus/portal_service/common/util/PortalReceive.class.php';

date_default_timezone_set('UTC');

class ConsumerProofread extends BaseConsumer
{
    protected function process(Stomp_Frame $message)
    {
		$start_time = microtime(TRUE);
		echo date('Y-m-d H:i:s') . ": Start import data to Portal Database ...\n";
		$return = true;
		$data = $message->map;

        $portal = new PortalReceive;
        $portal->setData($data);
        $result = $portal->receive();
		if ($result === FALSE) {
			$return = $this->sendErrorQueue($message);
		}

		$end_time = microtime(TRUE);
		$time_elapsed = $end_time - $start_time;
		echo date('Y-m-d H:i:s') . ": Import data completed. Time used: {$time_elapsed}s\n";
		return $return ;
	}
}

$cons = new ConsumerProofread(AC::CONFIG_MQ, 'PortalService');
try{
	$cons->run();
}catch(Stomp_Exception $e){
	mail(CommonUtils::getAdminMail(),"MQ Server Error, At ".trim(`hostname`) , print_r($e,1));
	echo "MQ Server Error!";
}
?>
